﻿/*
 * Project: IV:MP GUI Editor (http://code.google.com/p/ivmp-gui-editor)
 * Code license: GNU Lesser GPL (http://www.gnu.org/copyleft/lesser.html)
 * 
 * Authors: CrackHD
 * Description: 
 */

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace IvmpEditor
{
    public class Editor
    {
        public wndMain              MainWindow;
        public List<ETab>           Tabs;
        FindReplace.FindReplaceMgr  m_findReplaceMgr;
        wndTextOutput               m_compilerOutput;
        frmColorPicker              m_colorPicker;
        bool                        m_bWinformsStyles;
        static Editor               m_instance;
        public Editor(wndMain mainWindow)
        {
            if (m_instance != null)
                throw new InvalidOperationException("Singleton class Editor, instance already created...");
            m_instance = this;

            MainWindow = mainWindow;
            Tabs = new List<ETab>(5);
        }

        // Properties:
        public FindReplace.FindReplaceMgr FindReplaceMgr
        {
            get
            {
                if (m_findReplaceMgr == null)
                {
                    m_findReplaceMgr = new FindReplace.FindReplaceMgr() { OwnerWindow = MainWindow };
                    m_findReplaceMgr.Editors = new List<FindReplace.IEditor>();
                }
                return m_findReplaceMgr;
            }
        }
        public wndTextOutput CompilerOutputWindow
        {
            get
            {
                if (m_compilerOutput == null)
                    m_compilerOutput = new wndTextOutput(this) { Owner = MainWindow };

                return m_compilerOutput;
            }
        }
        public frmColorPicker ColorPicker
        {
            get
            {
                if (m_colorPicker == null)
                {
                    ActivateWinformsStyles();
                    m_colorPicker = new frmColorPicker();
                }

                return m_colorPicker;
            }
        }
        public bool ColorPickerVisible { get { return m_colorPicker != null && m_colorPicker.Visible; } }

        // Methods:
        public bool CheckExitAllowed()
        {
            // Check compile is on go:
            if (m_compilerOutput != null)
                if (m_compilerOutput.IsCompilingNow)
                    return false;

            if (m_colorPicker != null && m_colorPicker.Visible)
                m_colorPicker.Close();

            return true;
        }
        public void ActivateWinformsStyles()
        {
            if (m_bWinformsStyles)
                return;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(true);

            m_bWinformsStyles = true;
        }

        // Static:
        public static Editor GetInstance() { return m_instance; }
    }
}